/**
 *
 */
package demo.tellurium.module.cqp

import groovy.lang.MetaClass;
import demo.tellurium.framework.BaseUIModule;
import demo.util.BaseUtils;

/**
 * @author roger.xu
 *
 */
public class CQPLoginModule extends BaseUIModule {

    @Override
    public void defineUi() {
        ui.Container(uid: "CQPLogin", clocator: [tag: "form", method: "post", action: "j_security_check", name: "loginPage"]) {
            InputBox(uid: "Username", clocator: [tag: "input", type: "text", name: "j_username", id: "j_username"])
            InputBox(uid: "Password", clocator: [tag: "input", type: "password", name: "j_password", id: "j_password"])
            Button(uid: "SignIn", clocator: [tag: "button", type: "submit"])
        }
    }

    public static final String PATH_KEY = "cqp.login.path";

    public void doAdminLogin() {
        def username = BaseUtils.getProperty("cqp.admin.username");
        type "CQPLogin.Username", username
        pause 500

        def password = BaseUtils.getProperty("cqp.admin.password");
        type "CQPLogin.Password", password
        pause 500

        click "CQPLogin.SignIn"
        waitForPageToLoad 30000
    }

    public void doLogin(String username, String password) {
        type "CQPLogin.Username", username
        pause 500
        type "CQPLogin.Password", password
        pause 500
        click "CQPLogin.SignIn"
        waitForPageToLoad 30000
    }
}
